﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace ChessWebService.Models
{
    public class FriendDAO:DataProvider
    {

        public bool ThemBanBe(int Id1, int Id2)
        {
            try
            {
                connect();
                command = this.connection.CreateCommand();
                string query="insert into Friend(TaiKhoan01,TaiKhoan02) values(@TaiKhoan01,@TaiKhoan02)";
                command.CommandText = query;
                SqlParameter parameter;
                parameter = command.Parameters.Add("@TaiKhoan01", SqlDbType.Int);
                parameter.Value = Id1;

                parameter = command.Parameters.Add("@TaiKhoan02", SqlDbType.Int);
                parameter.Value = Id2;

                this.command.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool XoaBanBe(int Id1, int Id2)
        {
            try
            {
                connect();
                command = this.connection.CreateCommand();
                string query = "delete from Friend where  (TaiKhoan01=@Id01 and TaiKhoan02=@Id02) or (TaiKhoan01=@Id02 and TaiKhoan02=@Id01)";
                command.CommandText = query;
                SqlParameter parameter;
                parameter = command.Parameters.Add("@Id01", SqlDbType.Int);
                parameter.Value = Id1;

                parameter = command.Parameters.Add("@Id02", SqlDbType.Int);
                parameter.Value = Id2;

                this.command.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
            return false;
        }

    }
}